const app = getApp();
Page({
  data: {
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    cndUrl: app.domainName,
    tipNum:0,
    isX:'',
    isSmall:'',
    username:'',
    optionsShare:''
  },
  onLoad: function (options) {
    var _this=this;
    //options.share='ohFb-4_Ash3EzXhZhdFsYnG1ozHA';
    wx.request({ url: app.domainName+'web/?c=getname',data: {o:options.share},header: {'content-type': 'application/json' },success (res) {
      _this.setData({username:res.data.n});
    }}); 
    if (typeof(options.share) != "undefined" && "" != options.share){
         this.setData({optionsShare: options.share});
     }
     if(app.globalData.screenHeight < 1336){
        this.setData({isSmall:'s-'});
     }
     setTimeout(function(){
      wx.login({success (res) {
          app.globalData.loginCode=res.code;
          console.log(app.globalData.loginCode)
        }})
      }, 1000);

  },
  tohome: function() {
 
  },
  getPhoneNumber: function (e) {
    console.log(e)
    var _this=this;
     if (typeof(e.detail.iv) != "undefined" || "getPhoneNumber:ok" == e.detail.errMsg){
         wx.checkSession({
          success () {
            _this.decodePhone(app.globalData.loginCode,e.detail.iv,e.detail.encryptedData);
          },
          fail () {
            console.log('expire');
            wx.login({
              success (res) {
                  app.globalData.loginCode=res.code;
                  _this.decodePhone(app.globalData.loginCode,e.detail.iv,e.detail.encryptedData);
                  
              }})
          }
        })  
     }
  },
  decodePhone: function(_code,_iv,_encryptedData){
    var _this=this;
    wx.request({
      url: app.domainName + 'web/?c=checkphone',
      method: 'POST',
      data: {op:app.globalData.openid,cd: _code, iv:_iv,encryptedData:_encryptedData
      }, header: { 'content-type': 'application/x-www-form-urlencoded' },
      success: function (res) { 
          console.log(res)
          if('404' == res.data.msg){
              wx.redirectTo({url: '/pages/bei/index'})
          }
          if('no' == res.data.h){
              var _optionsShare=_this.data.optionsShare;
              if('' != _optionsShare){
                  wx.request({ url: app.domainName+'web/?c=sharelog',data: {zu: app.globalData.openid,o:_optionsShare},header: {'content-type': 'application/json' },success (res) {
                      app.globalData.entryIn='hashuinot';
                      wx.redirectTo({url: '/pages/index/index'})
                    }
                  }); 
              }else{
                wx.redirectTo({url: '/pages/index/index'})
              }
              
          }
          if('yes' == res.data.h){
             app.globalData.entryIn='hashuiok';
             wx.redirectTo({url: '/pages/index/index'})
          }
      }
    });
    app.linkflow.sendEvent({"event": "UDE_4034GAJFDSU","Click_akeyinclub": "被邀请页一键加入联盟按钮"})
  },
  onShareAppMessage: function (res) {
    return {
      title: '联盟集结令，精致Girl都已经加入就差你了！',
      path: '/pages/index/index?share='+app.globalData.openid,
      imageUrl:'https://elixir.omnimkt.com/elixir07/img/64.png'
    }
  }
})